//
//  TableViewCell.swift
//  Alamofire
//
//  Created by 李然 on 2022/7/20.
//

import UIKit
import SnapKit
import RxSwift

open class TableViewCell: UITableViewCell {
    
    let inset: CGFloat = 20
    
    public var cellDisposeBag = DisposeBag()
    
    open override func prepareForReuse() {
        super.prepareForReuse()
        cellDisposeBag = DisposeBag()
    }
    
    public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = .none
        makeUI()
    }
    
    required public init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    open override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
    }

    open func makeUI() {
        self.backgroundColor = R.color.common_2_bg_page()
        updateUI()
    }

    open func updateUI() {
        setNeedsDisplay()
    }
    
    open func bind(viewModel: Any) {
        
    }
    
    lazy var stackView: StackView = {
        let subviews: [UIView] = []
        let view = StackView(arrangedSubviews: subviews)
        view.axis = .horizontal
        view.alignment = .center
        view.distribution = .fill
        self.contentView.addSubview(view)
        view.snp.makeConstraints({ (make) in
            make.edges.equalToSuperview().inset(inset)
            make.height.greaterThanOrEqualTo(30)
        })
        return view
    }()
    
    public func getTableView() -> UITableView? {
        var cView = self.superview
        while let view = cView, !view.isKind(of: UITableView.self) {
            cView = view.superview
        }
        return cView as? UITableView
    }
}
